package com.own.component.elastic.core.base;

import com.own.component.elastic.model.CustomJoinField;
import lombok.AllArgsConstructor;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.List;

/**
 * ElasticFieldHandlerEnum
 * <p>
 * 后续自定义的字段处理器需要实现 BaseElasticFieldHandlerKey
 *
 * @author chenxueli
 * @date 2024-03-11 14:35:00
 */
@AllArgsConstructor
public enum ElasticFieldHandlerEnum implements BaseElasticFieldHandlerKey {

    ID(
            "ID",
            List.of(String.class, byte.class)
    ),

    BYTE(
            "BYTE",
            List.of(Byte.class, byte.class)
    ),

    DATE(
            "DATE",
            List.of(LocalDate.class)
    ),

    DATE_TIME(
            "DATE_TIME",
            List.of(LocalDateTime.class)
    ),

    DOUBLE(
            "DOUBLE",
            List.of(Double.class, double.class)
    ),

    GEO_POINT(
            "GEO_POINT",
            List.of(GeoPoint.class)
    ),

    INTEGER(
            "INTEGER",
            List.of(Integer.class, int.class)
    ),

    IP(
            "IP",
            List.of(String.class)
    ),

    LONG(
            "LONG",
            List.of(Long.class, long.class)
    ),

    NOTE(
            "NOTE",
            List.of(String.class)
    ),

    OBJECT(
            "OBJECT",
            List.of(Object.class)
    ),

    OFFSET_DATE_TIME(
            "OFFSET_DATE_TIME",
            List.of(ZonedDateTime.class)
    ),

    SHORT(
            "SHORT",
            List.of(Short.class, short.class)
    ),

    TEXT(
            "TEXT",
            List.of(String.class)
    ),

    TEXT_IK(
            "TEXT_IK",
            List.of(String.class)
    ),

    TEXT_TIME(
            "TEXT_TIME",
            List.of(String.class)
    ),

    TIME(
            "TIME",
            List.of(LocalTime.class)
    ),

    ZONED_DATE_TIME(
            "ZONED_DATE_TIME",
            List.of(ZonedDateTime.class)
    ),

    JOIN(
            "JOIN",
            List.of(CustomJoinField.class)
    ),
    ;

    /**
     * 操作的名称
     */
    private final String key;
    /**
     * 允许的类型信息
     */
    private final List<Class<?>> clazzList;

    /**
     * 操作的名称
     *
     * @return 名称
     */
    @Override
    public String key() {
        return this.key;
    }

    /**
     * 允许解析的类型列表
     *
     * @return 类型列表
     */
    @Override
    public List<Class<?>> clazzList() {
        return this.clazzList;
    }

}
